﻿using AccelerateSensor.Model.Gateway;
using AccelerateSensor.Model.Node;
using AccelerateSensor.Service.DbProxy.SQLite.Models;

namespace AccelerateSensor.Service.DbProxy.SQLite
{
    internal static class DataConverter
    {
        public static GatewayCommonAttributeInfo GetGatewayCommonAttributeInfo(
            GatewayCommonAttribute attribute)
        {
            return attribute == null
                ? null
                : new GatewayCommonAttributeInfo
                {
                    Ip = attribute.Ip,
                    TcpPort = attribute.TcpPort,
                    NetMask = attribute.NetMask,
                    NetGateway = attribute.NetGateway,
                    StatIntervalSec = attribute.StatIntervalSec
                };
        }

        public static GatewayPrivateAttributeInfo GetGatewayPrivateAttributeInfo(
            GatewayPrivateAttribute attribute)
        {
            return attribute == null
                ? null
                : new GatewayPrivateAttributeInfo
                {
                    StartFreq = attribute.StartFreq,
                    AntennaGain = attribute.AntennaGain,
                    RfChNum = attribute.RfChNum,
                    ChannelDataRate = attribute.ChannelDataRate
                };
        }

        public static GatewayCommonAttribute GetGatewayCommonAttribute(
            GatewayCommonAttributeInfo info, string gatewayUuid = "")
        {
            return info == null
                ? null
                : new GatewayCommonAttribute
                {
                    GatewayUuid = gatewayUuid,
                    Ip = info.Ip,
                    TcpPort = info.TcpPort,
                    NetMask = info.NetMask,
                    NetGateway = info.NetGateway,
                    StatIntervalSec = info.StatIntervalSec
                };
        }

        public static GatewayPrivateAttribute GetGatewayPrivateAttribute(
            GatewayPrivateAttributeInfo info, string gatewayUuid = "")
        {
            return info == null
                ? null
                : new GatewayPrivateAttribute
                {
                    GatewayUuid = gatewayUuid,
                    StartFreq = info.StartFreq,
                    AntennaGain = info.AntennaGain,
                    RfChNum = info.RfChNum,
                    ChannelDataRate = info.ChannelDataRate
                };
        }

        public static Gateway GetGateway(GatewayInfo info)
        {
            return info == null
                ? null
                : new Gateway
                {
                    Uuid = info.Uuid,
                    Type = info.Type,
                    LocalUpdateTime = info.LocalUpdateTime,
                    UpdateTime = info.UpdateTime
                };
        }

        public static NodeCommonAttributeInfo GetNodeCommonAttributeInfo(
            NodeCommonAttribute attribute)
        {
            return attribute == null
                ? null
                : new NodeCommonAttributeInfo
                {
                    SleepTimeSec = attribute.SleepTimeSec,
                    SendStatusIntervalMin = attribute.SendStatusIntervalMin,
                    PowerSource = attribute.PowerSource,
                    WorkMode = attribute.WorkMode,
                    SyncEnable = attribute.SyncEnable,
                    PowerVoltage = attribute.PowerVoltage,
                    NodeTemp = attribute.NodeTemp,
                    PowerSaving = attribute.PowerSaving
                };
        }

        public static NodePrivateAttributeInfo GetNodePrivateAttributeInfo(
            NodePrivateAttribute attribute)
        {
            return attribute == null
                ? null
                : new NodePrivateAttributeInfo
                {
                    AcquireDataType = attribute.AcquireDataType,
                    DataLength = attribute.DataLength,
                    SensorFreq = attribute.SensorFreq,
                    SensorRange = attribute.SensorRange,
                    XAcquireEnable = attribute.XAcquireEnable,
                    YAcquireEnable = attribute.YAcquireEnable,
                    ZAcquireEnable = attribute.ZAcquireEnable,
                    XTrigEnable = attribute.XTrigEnable,
                    YTrigEnable = attribute.YTrigEnable,
                    ZTrigEnable = attribute.ZTrigEnable,
                    TrigValue = attribute.TrigValue,
                    HighPassCutoffFreq = attribute.HighPassCutoffFreq
                };
        }

        public static NodeCommonAttribute GetNodeCommonAttribute(
            NodeCommonAttributeInfo info, string nodeUuid = "")
        {
            return info == null
                ? null
                : new NodeCommonAttribute
                {
                    NodeUuid = nodeUuid,
                    SleepTimeSec = info.SleepTimeSec,
                    SendStatusIntervalMin = info.SendStatusIntervalMin,
                    PowerSource = info.PowerSource,
                    WorkMode = info.WorkMode,
                    SyncEnable = info.SyncEnable,
                    PowerVoltage = info.PowerVoltage,
                    NodeTemp = info.NodeTemp,
                    PowerSaving = info.PowerSaving
                };
        }

        public static NodePrivateAttribute GetNodePrivateAttribute(
            NodePrivateAttributeInfo info, string nodeUuid = "")
        {
            return info == null
                ? null
                : new NodePrivateAttribute
                {
                    NodeUuid = nodeUuid,
                    AcquireDataType = info.AcquireDataType,
                    DataLength = info.DataLength,
                    SensorFreq = info.SensorFreq,
                    SensorRange = info.SensorRange,
                    XAcquireEnable = info.XAcquireEnable,
                    YAcquireEnable = info.YAcquireEnable,
                    ZAcquireEnable = info.ZAcquireEnable,
                    XTrigEnable = info.XTrigEnable,
                    YTrigEnable = info.YTrigEnable,
                    ZTrigEnable = info.ZTrigEnable,
                    TrigValue = info.TrigValue,
                    HighPassCutoffFreq = info.HighPassCutoffFreq
                };
        }

        public static Node GetNode(NodeInfo info)
        {
            return info == null
                ? null
                : new Node
                {
                    Uuid = info.Uuid,
                    GatewayUuid = info.GatewayUuid,
                    Type = info.Type,
                    LocalUpdateTime = info.LocalUpdateTime,
                    UpdateTime = info.UpdateTime
                };
        }
    }
}
